//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;

namespace EntLibContrib.Resource.Configuration
{
	/// <summary>
	/// Utility to return the default resource manager name, from the configuration source,
	/// if the given name is null
	/// </summary>
	internal class ResourceManagerDataRetriever : IConfigurationNameMapper
	{
		#region Public Methods
		/// <summary>
		/// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
		/// Returns the default resource manager name from the configuration in the <paramref name="configSource"/>, if the
		/// value for <paramref name="name"/> is <see langword="null"/> (<b>Nothing</b> in Visual Basic).
		/// </summary>
		/// <param name="name">The current name.</param>
		/// <param name="configurationSource">The source for configuration information.</param>
		/// <returns>
		/// The default resource manager name if <paramref name="name"/> is <see langword="null"/> (<b>Nothing</b> in Visual Basic),
		/// otherwise the original value for <b>name</b>.
		/// </returns>
		public string MapName(string name, IConfigurationSource configurationSource)
		{
			if ( name == null )
			{
				ResourceConfigurationView view = new ResourceConfigurationView(configurationSource);
				return view.DefaultResourceManager;
			}

			return name;
		}
		#endregion
	}
}